<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <style>
        .headline-content {
            padding: 5px 10px;
            max-width: 680px !important;
            margin:0 auto;
        }

        .div-margin {
            margin-bottom: 5px;
        }

        .title {
            color: #141414;
            font-size: 18px;
        }

        .tags .tag {
            display: inline-block;
            border: solid 1px #A3A3A3;
            padding: 2px 9px;
            border-radius: 11px;
            color: #A3A3A3;
            font-size: 12px;
            margin-right: 4px;
            min-width: 12px;
            text-align: center;
        }

        .head-icon-container {
            float: left;
        }

        .head-icon-container,
        .head-content{
            display: inline-block;
        }

        .head-content {
            margin-top: 3px;
            margin-left: 10px;
        }

        .head-icon {
            height: 40px;
            width: 40px;
            border-radius: 20px;
        }

        .author {
            height: 40px;
            margin-bottom: 10px;
        }

        .author-name ,
        .comment .cont .name{
            color: #A3A3A3;
            font-size: 12px;
        }
        .time{
            display: inline-block;
            color: #A3A3A3;
            font-size: 12px;
        }
        .comment-time {
            margin-top: 8px;
            font-size: 13px;
            color: #909399;
        }

        .flow {
            float: right;
        }
        .flow-image {
            height: 30px;
            margin-top: 5px;
        }

        .content {
            color: #141414;
            /*color: #606266;*/
            font-size: 14px;
        }

        .get-code-content{
            text-align: center;
            font-size: 12px;
            color: #606266;
        }
        .get-code{

        }
        .get-code-image {
            height: 25px;
            width: auto;
            margin-bottom: 4px;
        }

        .not-found{
            position: absolute;
            width: 100%;
            text-align: center;
            top: 50%;
            margin-top: -10px;
        }
        .comment .clearfix {
            position: relative;
            list-style: none;
            margin-left: 56px;
            padding: 12px 0 10px;
            border-bottom: 1px solid #F0F2F5;
        }
        .comment .clearfix .head {
            float: left;
            width: 40px;
            margin-left: -56px;
        }

        .comment .clearfix .head img{
            height: 40px;
            width: 40px;
            border-radius: 20px;
        }

        .comment .clearfix .info {
            line-height: 40px;
        }

        .comment .cont .support {
            float: right;
            margin-top: -7px;
            font-size: 12px;
            color: #909399;
        }
        .comment .cont .support .icon {
            position: relative;
            width: 17px;
            height: 15px;
            top: 2px;
        }
        .comment .cont .support .icon-txt {
            display: inline;
        }

        .comment .cont .txt {
            color: #606266;
            font-size: 14px;
        }

        .not-more {
            width: 100%;
            text-align: center;
            font-size: 13px;
            color: #909399;
        }

        .hide {
            display: none;
        }
    </style>
</head>
<body>
<div class="headline-content">
    <div class="title div-margin"></div>
    <div class="tags div-margin"></div>
    <div class="author div-margin">
        <div class="head-icon-container">
            <img class="head-icon" src="">
        </div>
        <div class="head-content">
            <div class="author-name"></div>
            <div class="time"></div>
        </div>

        <div class="flow">
            <img class="flow-image not-flow" src="css/image/flow.png">

        </div>
    </div>
    <div class="content div-margin"></div>

    <div class="comment div-margin">

    </div>

    <div class="not-more hide">
        <span class="tip-msg">没有更多评论了</span>
    </div>

    <!--
    <div class="get-code-content hide">
        <div class="get-code">
            <img class="get-code-image" src="css/image/get-code.png">
        </div>
        <span>领取</span>
    </div>
    -->
    <div class="not-found hide">
        <span class="tip-msg">文章内容未找到</span>
    </div>

    <div class="hide">
        <div class="item temp clearfix" comment-type="item">
            <!-- 头像 start -->
            <div class="head">
                <img class="c-avatar" src="//tva1.sinaimg.cn/crop.0.0.1080.1080.50/0064gR9Ojw8eyevgd6ejtj30u00u0q6v.jpg">
            </div><!-- 头像 end --><!-- 内容 start -->
            <div class="cont" comment-type="itemCont">
                <div class="info">
                    <span class="name">张三</span>
                    <div class="support">
                        <img class="icon" src="css/image/support.png">&nbsp;
                        <div class="icon-txt">
                            <span>赞</span>
                            <!--<em comment-type="voteNum">15</em>-->
                            <span class="voteNum"></span>
                        </div>
                    </div>
                </div>
                <div class="txt" comment-type="itemTxt">这真是极好的</div>
                <div class="comment-time">2017-7-19</div>
            </div><!-- 内容 end -->
        </div>
    </div>
</div>

<script src="/js/jquery.min.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript">
    $(function () {
        var getUrlParameter = function getUrlParameter(sParam) {
            var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;

            for (i = 0; i < sURLVariables.length; i++) {
                sParameterName = sURLVariables[i].split('=');

                if (sParameterName[0] === sParam) {
                    return sParameterName[1] === undefined ? true : sParameterName[1];
                }
            }
        };
        var uid = getUrlParameter("uid");
        var authorId = "";
        $.getJsonData("/api/news/queryNewsDetail?id=" + getUrlParameter("id") /*+ "&uid=" + uid*/,
            {}, {type: "Post", async: false}).done(function (result) {

            var headline = result.datas;
            if (headline == null /*|| headline.channelId != 3*/) {
                $(".not-found").removeClass("hide");
                return;
            }

            $(".title").html(headline.title);
            if (headline.tag && headline.tag.length > 0) {
                $(headline.tag.split(",")).each(function (index, tag) {
                    $(".tags").append(" <span class=\"tag\">" + tag + "</span>");
                });
            }

            $(".content").html(headline.content);
            var arr = headline.createTime.split(/[-:\/\s]/);
            var date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);

            $(".time").html(dateStr(date.getTime()));
            $(".author-name").html(headline.author);
            var avatar = headline.avatar;
            if (avatar == null || avatar == "") {
                avatar = "/css/image/avatar.png";
            }
            $(".head-icon").attr("src", avatar);
            // 显示评论
            showComment();

            /*
            $(".get-code-content").removeClass("hide");
            $(".flow").removeClass("hide");
            if (headline.isFollow) {
                flowed();
            } else {
                willFlow();
            }*/
            //是否已经阅读 - 领取火力值
            /*if (headline.isRead) {
                $(".get-code-content").addClass("hide");
            } else {
                $(".get-code-content").removeClass("hide");
            }
            authorId = headline.authorId;
            */
        });

        //获取评论  var ddd = function() 的方式不会预先加载
        function showComment() {
            $.getJsonData("/api/news/comments?pageSize=1000&pageNo=1&newsId=" + getUrlParameter("id") /*+ "&uid=" + uid*/,
                {},{type:"Post", async: false }).done(function (result) {
                var datas = result.datas;
                for(var i=0;i<datas.length;i++) {
                    var element = $(".item.temp").clone(true);
                    $(element).find(".name").html(datas[i].authorName);

                    var c_avatar = datas[i].userAvatar;
                    if (c_avatar == null || c_avatar == "") {
                        c_avatar = "/css/image/avatar.png";
                    }
                    $(element).find(".c-avatar").attr("src", c_avatar);
                    $(element).find(".txt").html(datas[i].content);

                    var arr = datas[i].createTime.split(/[-:\/\s]/);
                    var date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
                    $(element).find(".comment-time").html(dateStr(date.getTime()));
                    /*if(datas[i].supportAmount>0) {
                        $(element).find(".voteNum").html(datas[i].supportAmount);
                    }*/
                    $(element).removeClass("temp");
                    $(".comment").append($(element));
                }
                $(".not-more").removeClass("hide")
            });
        };

        // 评论点赞
        $(".headline-content").on("click", ".support .icon", function (e) {
            var r=confirm("是否下载火眼财经APP？");
            if (r) {
                window.location.href = "app-download.html"
            } else {
                return;
            }
        });

        /***** 以下部分关于逻辑处理部分，暂不使用******************************/
        //关注 -> 提示下载
        $(".headline-content").on("click", ".flow-image.not-flow", function (e) {
            var r=confirm("是否下载火眼财经APP？");
            if (r) {
                window.location.href = "app-download.html"
            } else {
                return;
            }
            /*if( notLogin(uid) ){
                alert("用户尚未登录！" );
                return ;
            }
            $.getJsonData("/api/news/operat?operatType=03&uid=" + uid + "&authorId=" + authorId,
                {},{type:"Post"}).done(function (result) {
                if(result.code == "200") {
                    alert("关注成功 " );
                    flowed();
                } else {
                    willFlow();
                    alert(result.message)
                }
            });*/
        });

        //取消关注
        $(".headline-content").on("click", ".flow-image.flowed", function (e) {
            if( notLogin(uid) ){
                alert("用户尚未登录！" );
                return ;
            }
            var r=confirm("确定要取消关注该作者吗？");
            if(!r) {
                return ;
            }

            $.getJsonData("/api/news/operat?operatType=04&uid=" + uid + "&authorId=" + authorId,
                {},{type:"Post"}).done(function (result) {
                if(result.code == "200") {
                    alert("取消关注成功 " );
                    willFlow();
                } else {
                    flowed();
                    alert(result.message);
                }
            });
        });


        //领取火力值
        $(".headline-content").on("click", ".get-code", function (e) {
            if( notLogin(uid) ){
                alert("用户尚未登录！" );
                return ;
            }
            $.getJsonData("/api/profit/getProfit?type=02&uid=" + uid + "&newsId=" + getUrlParameter("id"),
                {},{type:"Get", async: false }).done(function (result) {

                if (result.code == "200") {
                    alert("成功领取火力值：" + result.datas );
                    $(".get-code-content").addClass("hide");
                } else {
                    alert(result.message);
                    $(".get-code-content").removeClass("hide");
                }
            });

            $.getJsonData("/api/news/operat?operatType=00&uid=" + uid + "&newsId=" + getUrlParameter("id"),
                {},{type:"Get", async: false }).done(function (result) {
                //console.log(result.message + "::阅读");
            });
        });

        /**
         * 毫秒转换友好的显示格式
         * 输出格式：21小时前
         * @param  {[type]} time [description]
         * @return {[type]}      [description]
         */
        function dateStr(date) {
            //获取js 时间戳
            var time = new Date().getTime();
            //去掉 js 时间戳后三位
            time = parseInt((time - date) / 1000);

            //存储转换值
            var s;
            if (time < 60 * 10) {//十分钟内
                return '刚刚';
            } else if ((time < 60 * 60) && (time >= 60 * 10)) {
                //超过十分钟少于1小时
                s = Math.floor(time / 60);
                return s + "分钟前";
            } else if ((time < 60 * 60 * 24) && (time >= 60 * 60)) {
                //超过1小时少于24小时
                s = Math.floor(time / 60 / 60);
                return s + "小时前";
            } else {
                //超过24小时
                var date = new Date(date);
                return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            }
        }

        //已经关注状态
        function flowed(){
            $(".flow-image").attr("src", "css/image/flowed.png");
            $(".flow-image").removeClass("not-flow");
            $(".flow-image").addClass("flowed");
        }

        //未关注状态
        function willFlow(){
            $(".flow-image").attr("src", "css/image/flow.png");
            $(".flow-image").removeClass("flowed");
            $(".flow-image").addClass("not-flow");
        }

        function notLogin(uid) {
            if ( uid == undefined ) {
                return true;
            }
            if ((typeof uid) == "string" && uid.length==0) {
                return true;
            }
            if ((typeof uid) == "boolean") {
                return true;
            }
            return false;
        }


        window.alert = function(name){
            var iframe = document.createElement("IFRAME");
            iframe.style.display="none";
            iframe.setAttribute("src", 'data:text/plain');
            document.documentElement.appendChild(iframe);
            window.frames[0].window.alert(name);
            iframe.parentNode.removeChild(iframe);
        };

    });
</script>
</body>
</html>